package com.gduf.lsm.service;


import cn.hutool.core.util.ObjectUtil;
import com.gduf.lsm.common.enums.ResultCodeEnum;
import com.gduf.lsm.entity.WaterBill;
import com.gduf.lsm.exception.CustomException;
import com.gduf.lsm.mapper.WaterBillMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告信息表业务处理
 **/
@Service
public class WaterBillService {

    @Autowired
    private WaterBillMapper waterBillMapper;

    /**
     * 新增
     * @param waterBill
     */
    public void add(WaterBill waterBill) {
        //判断公告标题、内容和通知对象不为空才可以插入
        /*if(ObjectUtil.isEmpty(waterBill.getTitle())||ObjectUtil.isEmpty(waterBill.getContent())||ObjectUtil.isEmpty(waterBill.getChara())){
            throw new CustomException(ResultCodeEnum.NOTICE_MAIN_NULL_ERROR);
        }*/
        waterBillMapper.insert(waterBill);
    }

    /**
     * 删除
     * @param id
     */
    public void deleteById(Integer id) {
        waterBillMapper.deleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            waterBillMapper.deleteById(id);
        }
    }

    /**
     * 修改
     * @param waterBill
     */
    public void updateById(WaterBill waterBill) {
        waterBillMapper.updateById(waterBill);
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    public WaterBill selectById(Integer id) {
        return waterBillMapper.selectById(id);
    }

    /**
     * 查询所有
     * @param waterBill
     * @return
     */
    public List<WaterBill> selectAll(WaterBill waterBill) {
        return waterBillMapper.selectAll(waterBill);
    }

    /**
     * 分页查询
     * @param waterBill
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<WaterBill> selectPage(WaterBill waterBill, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<WaterBill> list = waterBillMapper.selectAll(waterBill);
        return PageInfo.of(list);
    }

    public List<WaterBill> selectByUserId(Integer userId) {
        WaterBill w=new WaterBill();
        w.setUserId(userId);
        return waterBillMapper.selectAll(w);
    }
}